package com.boco.wmworkflow.common.xmlmodel;

import com.boco.common.util.xml.AbstractXmlModel;
import com.boco.common.util.xml.*;
import com.boco.webmaster.common.xsdmap.workflow.wfaction.*;
import java.util.*;

public class WfActionXmlModel  extends AbstractXmlModel{
    private Map actionMap = new HashMap();
    private static WfActionXmlModel instance;

    public static WfActionXmlModel getInstance(){
        return instance;
    }

    public static void createInstance(String xmlFileName) throws Exception{
        if(instance == null){
            instance = new WfActionXmlModel(xmlFileName);
        }
    }

    private WfActionXmlModel(String xmlFileName)throws Exception{
        super("com.boco.webmaster.common.xsdmap.workflow.wfaction", xmlFileName);
        WfActionModelType model = getXmlRootModel();
        List actionList = model.getActionList();
        for(int i=0; i<actionList.size(); i++){
            ActionType action = (ActionType) actionList.get(i);
            actionMap.put(createKey(action.getProcessId(), action.getProcessType()), action);
        }
    }

    public ActionType getProcessAction(String processId, int processType){
        return (ActionType) actionMap.get(createKey(processId, processType));
    }

    public String getActionFormClassName(String processId, int processType, String formName){
        String formClassName = null;
        ActionType action = getProcessAction(processId, processType);
        for(int i=0; i<action.getFormList().size(); i++){
            FormType form = (FormType) action.getFormList().get(i);
            if(formName.equals(form.getFormName())){
                formClassName = form.getFormClassName();
                break;
            }
        }
        return formClassName;
    }

    private WfActionModelType getXmlRootModel(){
        return (WfActionModelType) super.getRootModel();
    }

    private static String createKey(String processId, int processType){
        return processId + processType;
    }
}
